package com.zzw.test;

/**
 * @author zzw
 * @see
 * @since 2018/2/12
 */
public class MyThread implements Runnable {

    private static String globalBuffer = "";
    private String m_msg;

    public static void main(String[] args) {
        Thread t1 = new Thread(new MyThread("A"), "Thread-A");
        Thread t2 = new Thread(new MyThread("B"), "Thread-B");

        t1.start();
        t2.start();
    }

    public MyThread(String msg) {
        m_msg = msg;
    }

    public static void print(String msg) {
        globalBuffer = msg;
        System.out.println(Thread.currentThread().getName() + ": " + globalBuffer);
    }

    @Override
    public void run() {
        try {
            while (true) {
                print(m_msg);
                Thread.sleep(500);
            }
        } catch(Exception e) {}
    }

}
